//
//  LLHTTPSessionManager.h
//  lrlzapp
//
//  Created by dl on 16/2/24.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import <AFNetworking/AFNetworking.h>
#import "LLUser.h"

//typedef void (^HttpCompletionBlock) (NSURLSessionDataTask *task, id json);
//typedef void (^HttpFailueBlock)(NSURLSessionDataTask *task, NSError *error);

typedef enum HttpMethodType {
    GET_TYPE, POST_TYPE
} HttpMethodType;

#define INT_NETWORK_TIMEOUT 30
#define HTTP_ACCEPTABLE_CONTENT_TYPES [NSSet setWithObjects:@"application/json", @"text/html", @"text/json", @"text/javascript", @"text/plain", nil]

extern NSString *const OCTClientErrorDomain;
extern const NSInteger OCTClientErrorAuthenticationFailed;
extern const NSInteger OCTClientErrorRequestForbidden;
extern const NSInteger OCTClientErrorBadRequest;
extern const NSInteger OCTClientErrorConnectionFailed;
extern const NSInteger OCTClientErrorJSONParsingFailed;

@interface LLHTTPSessionManager : AFHTTPSessionManager

+ (LLHTTPSessionManager *)shareManager;

@property(nonatomic, strong, readonly) LLUser *user;
@property(nonatomic, getter = isAuthenticated, readonly) BOOL authenticated;
@property(nonatomic, copy, readonly) NSString *token;

+ (NSError *)userRequiredError;

+ (NSError *)authenticationRequiredError;

- (RACSignal *)loginWithUser:(LLUser *)user;

- (RACSignal *)request:(NSString *)url
           resultClass:(Class)resultClass;

- (RACSignal *)request:(NSString *)url
                params:(NSDictionary *)params
           resultClass:(Class)resultClass;

- (RACSignal *)request:(NSString *)url
                params:(id)params
                method:(HttpMethodType)method
           resultClass:(Class)resultClass;

- (RACSignal *)request:(NSString *)url
                params:(id)params
              fileData:(NSData *)fileData
              fileName:(NSString *)fileName
           resultClass:(Class)resultClass;

@end